require(["config"], function(config) {
	require([ "jquery","sw"], function( jq,sw) {
		
		//轮播图
		var mySwiper = new Swiper(".swiper-container",{
			loop:true,
			autoplay:2000,
			effect : 'fade',			
			paginationClickable :true,
			updateOnImagesReady : true,
			autoplayDisableOnInteraction : false,
			pagination: '.swiper-pagination'
		});
							
		//二级菜单
		$(function(){
			$(".nav_menu a").mouseenter(function(){
			
				var index = $(this).index();
				$(".nav_menu .headlist").eq(index).css("display","block" 	)				             
			})				
			$(".nav_menu").mouseleave(function(){
				$(".nav_menu .headlist").css("display","none");
				
			})
		});
		/*--------------------------JSON获取图片---------------------------------*/			
		
		$(function(){
			$.getJSON("scss/index.json",function(a){
				//品牌闪购	
				var flash = a.flash.img;
				var star = a.flash.one;
				var two = a.flash.two;
				var three = a.flash.three;
				var time = a.flash.time;
				var lov = a.flash.key;
				var remind = a.flash.remind;
				jq.each(flash,function(i){
					
					$("<div class='list_item_br'> <div class='di-prddiv'><div class='tt_tags'><div class='lable tt_tag_c'>" + lov[i] + 
						"</div></div><div class='pp_img'><a target='_blank' href=''><img title=''src='" + flash[i] +
						"'/></a><div class='pp_remind'><div class='pp_remind_bg'><input type='text' placeholder='填写手机号码' id='phone_8'><a href=''>开售提醒</a></div></div> </div><div class='pinpai_name'><div class='pp_name_left'> <p class='di_p1'><a href='' target='_blank'>" 
						+ star[i] + "</a></p><p class='di_p2'>" + two[i]+ "</p></div></div><div class='pp_bt'><div class='di_p3'>全场<span>" + three[i] + 
						"</span></div><div class='pp_time'><span class='box3' >" + time[i] + "</span></div></div></div></div>")
					.appendTo($(".ppsg_pic")); 						                        	
				});
				//今日闪购
				var img = a.day.src;
				var discount = a.day.discount;
				var describe = a.day.describe;
				var price = a.day.price;
				var y_price = a.day.y_price;
				var people = a.day.people;
				jq.each(img,function(j){
					
					$(" <li class='hsgp left'> <a href=''><img src='" + img[j] + " 'alt=''/></a><a href='' class='hsgp_tip'><span>" + discount[j] + "/</span>" + describe[j] +
					"</a><div class='hsgp_price'><span class='left span1'><em>¥</em>" + price[j] + 
					" <del><em>¥</em>" + y_price[j] + "</del></span><a href='' class='right'></a> <span class='right span2'>" + people[j] + "人<em>已购买</em> </span> </div></li>")
					.appendTo($(".jrsg_pic_list"));
				})
			})
			
		});
		
		
		//楼层
		new Go_floor('.floor_nav','.floor_nave');//楼层跳转		
		$(window).scroll(function(){		
			if($('body').scrollTop()>500){
				$('#floor').fadeIn();
			}else{
				$('#floor').fadeOut()
			}
		})
		function Go_floor(name1,name2){
		//console.log($('#gotop'))
		//console.log($('.floor_nav'))
			var _this = this;
			var value = null;
			$(name1).on('click',function(){
				//console.log($(this).index())
				value = $(this).index()
				_this.leave(name1,value)
				_this.change($(this).index(),name1);
				_this.jump($(this).index(),name2);
				
			})
			$(name1).on('mouseenter',function(){
				//console.log($(this).children())
				_this.leave(name1,value)
				_this.change($(this).index(),name1);
			})
		}
		Go_floor.prototype.jump = function(num,name){
			$('body,html').stop().animate({
				scrollTop:$(name).eq(num).offset().top
			})
		}
		Go_floor.prototype.change = function(num,name){
			var str = '#333 url(scss/img/headlogo/nav_leftbg2.png) no-repeat 0 '+(-71*num)+'px';
				//console.log(str)
			$(name).eq(num).children().css({
				'background':str,
				color:"white"
			})
		}
		Go_floor.prototype.leave = function(name,sum){
			//console.log($('.floor_nav').children().length)
			for(var i = 0 ; i < $(name).children().length ; i++){
				if(i != sum ){
					var str = 'white url(scss/img/headlogo/nav_leftbg1.png) no-repeat 0 '+(-71*i)+'px';
					$(name).children().eq(i).css({
						'background':str,
						color:"#333"
					})
				}
			}
		} 
		
		
		
		
		//选项卡
		 new Tab();
		function Tab(){
			var _this = this;
			this.tab = $('body').children('#main').find('.tab');
			//console.log(this.tab)
			this.underline =  $('body').children('#main').find('.underline');
	
			this.ul = $('body').children('#main').find('.hsg_ul');
			//console.log(this.ul)
			this.tab.on('mouseenter',function(){
	
				_this.move($(this).index());
			})
			this.tab.on('click',function(){
				_this.click($(this).index());
			})
		}
		Tab.prototype.move = function(sum){
			this.underline.stop().animate({
				left:sum*this.tab.eq(sum).outerWidth()
			})
		}
		Tab.prototype.click = function(sum){
			this.underline.css('left',sum*this.tab.eq(sum).outerWidth());
			this.tab.eq(sum).children().css({
				'color':'#ed145b',
				'background-position-X':'-147px'
			});
			this.tab.eq(sum).siblings().children().css({
				'color':'#333',
				'background-position-X':'0px'
			});
			if(sum == 0 || sum == 1){
				this.ul.eq(sum).fadeIn().siblings().fadeOut();
			}
		}
		
		//返回顶部
		$("#gotop").click(function() {
			$("html,body").animate({
				scrollTop: 0
			}, 0);
		});
		$(".mpbtn_cart").click(function() {
			$(".gouwu").toggle();
		})
			
	});
});